package etf.hibernate;

import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;
import org.hibernate.bytecode.buildtime.Logger;
import org.hibernate.cfg.Configuration;
import org.slf4j.LoggerFactory;

public class TestHibernate {
	
	
	
	public static void main (String args[]){
		// Create SessionFactory and Session object
    SessionFactory sessions = new Configuration().configure().buildSessionFactory();
    Session session = sessions.openSession();
    
    // Perform life-cycle operations under a transaction
    Transaction tx = null;
    try {
        tx = session.beginTransaction();
        
        // 
        long total = 0;
        long startTime = System.currentTimeMillis();
		for (int i = 0; i < 100000; i++) {
			SimpleClass p1 = new SimpleClass(i,i,"test" + i);
			session.save(p1);
			//total += i;
		
		}
		tx.commit();
		long stopTime = System.currentTimeMillis();
		long elapsedTime = stopTime - startTime;
		System.out.println("Proteklo vrijeme:" + elapsedTime);
        
        // Create another Person object and save it.
        //SimpleClass p2 = new SimpleClass(2,2,"test2");
        //session.save(p2); 1hilj-12269  50hiljada 6044    25hiljada 3232  10hilj 1415
        
        // Retrieve the person objects
       //SimpleClass person = (SimpleClass)session. get(SimpleClass.class, p1.getId());
       //System.out.println("First person retrieved = " + person.getField3());
                
        
        tx = null;
    } catch ( HibernateException e ) {
        if ( tx != null ) tx.rollback();
        e.printStackTrace();
    } finally {
        session.close();
    }
    
    // Display tables
   // HibernateUtil.checkData("select * from simple");
		
	}
		
}
